package DFS_543;

import LCommon.TreeNode;

public class Solution {
    int max=0;
    public int diameterOfBinaryTree(TreeNode root) {
        if(root !=null){
            getDepth(root);
            return max;
        }
        return 0;
    }
    public int getDepth(TreeNode root){
        if(root!=null){
            int right = getDepth(root.right);
            int left = getDepth(root.left);
            if(right+left>max){
                max = right+left;
            }
            return Math.max(right,left)+1;
        }
        return 0;
    }
	
}
